package com.zengqingfa.examples.mybatisplus.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.sql.PreparedStatement;

/**
 * @fileName: UserService2
 * @author: zengqf3
 * @date: 2021-7-2 9:19
 * @description:
 */
@Service
public class UserService2 {

    @Autowired
    JdbcTemplate jdbcTemplate;

    @Transactional(rollbackFor = Exception.class)
    public void updateById() throws Exception{
        String code = "role4444";
        Integer id = 1;
        String sql = "update role set code=? where id =?";
        jdbcTemplate.update(sql, code, id);
        throw new Exception("1111");
    }

    @Transactional(rollbackFor = Exception.class)
    private void updateByIdPrivateMethod() throws Exception{
        String code = "role555";
        Integer id = 1;
        String sql = "update role set code=? where id =?";
        jdbcTemplate.update(sql, code, id);
        throw new Exception("2222");
    }

    public void updateById2() throws Exception{
        this.updateByIdPrivateMethod();
    }
}
